using System.Collections;
using System.Collections.Generic;
using System.Runtime.InteropServices;
using Unity.VisualScripting;
using UnityEditor.Rendering;
using UnityEngine;

public class FishInCase : MonoBehaviour
{

    public Vector3 outPosition;
    public Vector3 stopPosition;
    public float speed = 2f;

    public GameObject talk;

    float waitTik = 2f;

    bool isStop = true;
    void OnEnable(){
        talk.SetActive(false);
        EventHandler_Prop.CaseOpenEvent += OnCaseOpenEvent;
    }

    void Update(){
        if(!isStop){
            waitTik -= Time.deltaTime;
            if(waitTik < 0){
                transform.position = Vector3.MoveTowards(transform.position, stopPosition, speed * Time.deltaTime);
                if(transform.position == stopPosition){
                    isStop = true;
                    talk.SetActive(false);
                    EventHandler_Prop.CallFishInCaseStopEvent();
                }
            }
        }
    }

    void OnCaseOpenEvent(){
        transform.position = outPosition;
        if(transform.position != stopPosition){
            talk.SetActive(true);
            isStop = false;
        }
    }

    void OnDisable(){
        EventHandler_Prop.CaseOpenEvent -= OnCaseOpenEvent;
    }

}
